package spring.demo8.service.impl;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;

import spring.demo8.bean.StudentsBean;
import spring.demo8.bean.SutdentsRowMapper;
import spring.demo8.service.IStudentService;

public class StudentServiceImpl implements IStudentService{

	private JdbcTemplate jdbc;
	
	public void setDataSource(DataSource ds) {
		this.jdbc = new JdbcTemplate(ds);
	}
	
	@Override
	public void save(StudentsBean bean) throws Exception{
		jdbc.update("Insert into students ( stu_name , stu_age , stu_gender ) values (?,?,?)" ,
				new Object[] {bean.getName(),bean.getAge(),bean.getGengder() },
				new int[] {java.sql.Types.VARCHAR,java.sql.Types.INTEGER,java.sql.Types.INTEGER} );
	}

	@Override
	public List<StudentsBean> findAll() {
		List<StudentsBean> li = jdbc.query("select * from students", new SutdentsRowMapper());
		return li;
	}

}
